package org.openinsula.arena.aws.integration.sqs;

import javax.annotation.Resource;

import org.openinsula.arena.aws.AwsConstants;
import org.openinsula.arena.aws.sqs.SqsManager;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.util.Assert;

import com.xerox.amazonws.sqs2.SQSException;

/**
 * A ServiceActivator implementation for sending messages to Amazon SQS.
 * 
 * <p>
 * The {@link AwsConstants#SQS_QUEUE_NAME} header is required.
 * 
 * @see AwsConstants
 * 
 * @author Edson Yanaga
 */
public class SqsSendingService implements InitializingBean {

	@Resource(name = "sqsManager")
	private SqsManager sqsManager;

	private String queueName;

	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(sqsManager, "'sqsManager' must not be null");
		Assert.notNull(queueName, "'queueName' must not be null");
	}

	@ServiceActivator
	public void send(String value) throws SQSException {
		sqsManager.put(queueName, value);
	}

	public void setSqsManager(SqsManager sqsManager) {
		this.sqsManager = sqsManager;
	}

	public void setQueueName(String queueName) {
		this.queueName = queueName;
	}

}
